
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>2.1 第一节 · 这是我的第一本gitbook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="景智君">
        <meta name="identifier" content="图书编号" scheme="ISBN">
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="./" />
    
    
    <link rel="prev" href="../chapter-1/" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">第一章</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../chapter-1/ch1.html">
            
                <a href="../chapter-1/ch1.html">
            
                    
                    1.1 第一节
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter-1/writing.html">
            
                <a href="../chapter-1/writing.html">
            
                    
                    1.2 第二节
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter-1/">
            
                <a href="../chapter-1/">
            
                    
                    1.3 第三节
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第二章</li>
        
        
    
        <li class="chapter active" data-level="2.1" data-path="ch2.html">
            
                <a href="ch2.html">
            
                    
                    2.1 第一节
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="./">
            
                <a href="./">
            
                    
                    2.2 第二节
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../">
            
                <a href="../">
            
                    
                    README
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >2.1 第一节</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <blockquote>
<p>&#x6982;&#x8981;&#x6587;&#x4EF6;&#x4E3B;&#x8981;&#x5B58;&#x653E; GitBook &#x7684;&#x6587;&#x4EF6;&#x76EE;&#x5F55;&#x4FE1;&#x606F;&#xFF0C;&#x5DE6;&#x4FA7;&#x7684;&#x76EE;&#x5F55;&#x5C31;&#x662F;&#x6839;&#x636E;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x6765;&#x751F;&#x6210;&#x7684;&#xFF0C;
&#x9ED8;&#x8BA4; &#x5BF9;&#x5E94;&#x7684;&#x6587;&#x4EF6;&#x662F; SUMMARY.md&#xFF0C;&#x53EF;&#x4EE5;&#x5728; book.json &#x91CD;&#x65B0;&#x5B9A;&#x4E49;&#x8BE5;&#x6587;&#x4EF6;&#x7684;&#x5BF9;&#x5E94;&#x503C;&#x3002;
&#x5B83;&#x901A;&#x8FC7;  Markdown &#x4E2D;&#x7684;&#x5217;&#x8868;&#x8BED;&#x6CD5;&#x6765;&#x8868;&#x793A;&#x6587;&#x4EF6;&#x7684;&#x7236;&#x5B50;&#x5173;&#x7CFB;&#xFF0C;&#x4E0B;&#x9762;&#x662F;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x793A;&#x4F8B;&#xFF1A;</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;./fs.js&apos;</span>)
<span class="hljs-keyword">var</span> constants = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;constants&apos;</span>)

<span class="hljs-keyword">var</span> origCwd = process.cwd
<span class="hljs-keyword">var</span> cwd = <span class="hljs-literal">null</span>

<span class="hljs-keyword">var</span> platform = process.env.GRACEFUL_FS_PLATFORM || process.platform

process.cwd = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">if</span> (!cwd)
    cwd = origCwd.call(process)
  <span class="hljs-keyword">return</span> cwd
}
<span class="hljs-keyword">try</span> {
  process.cwd()
} <span class="hljs-keyword">catch</span> (er) {}

<span class="hljs-keyword">var</span> chdir = process.chdir
process.chdir = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">d</span>) </span>{
  cwd = <span class="hljs-literal">null</span>
  chdir.call(process, d)
}

<span class="hljs-built_in">module</span>.exports = patch

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">patch</span> (<span class="hljs-params">fs</span>) </span>{
  <span class="hljs-comment">// (re-)implement some things that are known busted or missing.</span>

  <span class="hljs-comment">// lchmod, broken prior to 0.6.2</span>
  <span class="hljs-comment">// back-port the fix here.</span>
  <span class="hljs-keyword">if</span> (constants.hasOwnProperty(<span class="hljs-string">&apos;O_SYMLINK&apos;</span>) &amp;&amp;
      process.version.match(<span class="hljs-regexp">/^v0\.6\.[0-2]|^v0\.5\./</span>)) {
    patchLchmod(fs)
  }

  <span class="hljs-comment">// lutimes implementation, or no-op</span>
  <span class="hljs-keyword">if</span> (!fs.lutimes) {
    patchLutimes(fs)
  }

  <span class="hljs-comment">// https://github.com/isaacs/node-graceful-fs/issues/4</span>
  <span class="hljs-comment">// Chown should not fail on einval or eperm if non-root.</span>
  <span class="hljs-comment">// It should not fail on enosys ever, as this just indicates</span>
  <span class="hljs-comment">// that a fs doesn&apos;t support the intended operation.</span>

  fs.chown = chownFix(fs.chown)
  fs.fchown = chownFix(fs.fchown)
  fs.lchown = chownFix(fs.lchown)

  fs.chmod = chmodFix(fs.chmod)
  fs.fchmod = chmodFix(fs.fchmod)
  fs.lchmod = chmodFix(fs.lchmod)

  fs.chownSync = chownFixSync(fs.chownSync)
  fs.fchownSync = chownFixSync(fs.fchownSync)
  fs.lchownSync = chownFixSync(fs.lchownSync)

  fs.chmodSync = chmodFixSync(fs.chmodSync)
  fs.fchmodSync = chmodFixSync(fs.fchmodSync)
  fs.lchmodSync = chmodFixSync(fs.lchmodSync)

  <span class="hljs-comment">//fs.stat = statFix(fs.stat)</span>
  <span class="hljs-comment">//fs.fstat = statFix(fs.fstat)</span>
  <span class="hljs-comment">//fs.lstat = statFix(fs.lstat)</span>

  fs.statSync = statFixSync(fs.statSync)
  fs.fstatSync = statFixSync(fs.fstatSync)
  fs.lstatSync = statFixSync(fs.lstatSync)

  <span class="hljs-comment">// if lchmod/lchown do not exist, then make them no-ops</span>
  <span class="hljs-keyword">if</span> (!fs.lchmod) {
    fs.lchmod = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">path, mode, cb</span>) </span>{
      <span class="hljs-keyword">if</span> (cb) process.nextTick(cb)
    }
    fs.lchmodSync = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{}
  }
  <span class="hljs-keyword">if</span> (!fs.lchown) {
    fs.lchown = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">path, uid, gid, cb</span>) </span>{
      <span class="hljs-keyword">if</span> (cb) process.nextTick(cb)
    }
    fs.lchownSync = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{}
  }

  <span class="hljs-comment">// on Windows, A/V software can lock the directory, causing this</span>
  <span class="hljs-comment">// to fail with an EACCES or EPERM if the directory contains newly</span>
  <span class="hljs-comment">// created files.  Try again on failure, for up to 60 seconds.</span>

  <span class="hljs-comment">// Set the timeout this long because some Windows Anti-Virus, such as Parity</span>
  <span class="hljs-comment">// bit9, may lock files for up to a minute, causing npm package install</span>
  <span class="hljs-comment">// failures. Also, take care to yield the scheduler. Windows scheduling gives</span>
  <span class="hljs-comment">// CPU to a busy looping process, which can cause the program causing the lock</span>
  <span class="hljs-comment">// contention to be starved of CPU by node, so the contention doesn&apos;t resolve.</span>
  <span class="hljs-keyword">if</span> (platform === <span class="hljs-string">&quot;win32&quot;</span>) {
    fs.rename = (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">fs$rename</span>) </span>{ <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">from, to, cb</span>) </span>{
      <span class="hljs-keyword">var</span> start = <span class="hljs-built_in">Date</span>.now()
      <span class="hljs-keyword">var</span> backoff = <span class="hljs-number">0</span>;
      fs$rename(from, to, <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">CB</span> (<span class="hljs-params">er</span>) </span>{
        <span class="hljs-keyword">if</span> (er
            &amp;&amp; (er.code === <span class="hljs-string">&quot;EACCES&quot;</span> || er.code === <span class="hljs-string">&quot;EPERM&quot;</span>)
            &amp;&amp; <span class="hljs-built_in">Date</span>.now() - start &lt; <span class="hljs-number">60000</span>) {
          setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
            fs.stat(to, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">stater, st</span>) </span>{
              <span class="hljs-keyword">if</span> (stater &amp;&amp; stater.code === <span class="hljs-string">&quot;ENOENT&quot;</span>)
                fs$rename(from, to, CB);
              <span class="hljs-keyword">else</span>
                cb(er)
            })
          }, backoff)
          <span class="hljs-keyword">if</span> (backoff &lt; <span class="hljs-number">100</span>)
            backoff += <span class="hljs-number">10</span>;
          <span class="hljs-keyword">return</span>;
        }
        <span class="hljs-keyword">if</span> (cb) cb(er)
      })
    }})(fs.rename)
  }

  <span class="hljs-comment">// if read() returns EAGAIN, then just try it again.</span>
  fs.read = (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">fs$read</span>) </span>{ <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">fd, buffer, offset, length, position, callback_</span>) </span>{
    <span class="hljs-keyword">var</span> callback
    <span class="hljs-keyword">if</span> (callback_ &amp;&amp; <span class="hljs-keyword">typeof</span> callback_ === <span class="hljs-string">&apos;function&apos;</span>) {
      <span class="hljs-keyword">var</span> eagCounter = <span class="hljs-number">0</span>
      callback = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">er, _, __</span>) </span>{
        <span class="hljs-keyword">if</span> (er &amp;&amp; er.code === <span class="hljs-string">&apos;EAGAIN&apos;</span> &amp;&amp; eagCounter &lt; <span class="hljs-number">10</span>) {
          eagCounter ++
          <span class="hljs-keyword">return</span> fs$read.call(fs, fd, buffer, offset, length, position, callback)
        }
        callback_.apply(<span class="hljs-keyword">this</span>, <span class="hljs-built_in">arguments</span>)
      }
    }
    <span class="hljs-keyword">return</span> fs$read.call(fs, fd, buffer, offset, length, position, callback)
  }})(fs.read)

  fs.readSync = (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">fs$readSync</span>) </span>{ <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">fd, buffer, offset, length, position</span>) </span>{
    <span class="hljs-keyword">var</span> eagCounter = <span class="hljs-number">0</span>
    <span class="hljs-keyword">while</span> (<span class="hljs-literal">true</span>) {
      <span class="hljs-keyword">try</span> {
        <span class="hljs-keyword">return</span> fs$readSync.call(fs, fd, buffer, offset, length, position)
      } <span class="hljs-keyword">catch</span> (er) {
        <span class="hljs-keyword">if</span> (er.code === <span class="hljs-string">&apos;EAGAIN&apos;</span> &amp;&amp; eagCounter &lt; <span class="hljs-number">10</span>) {
          eagCounter ++
          <span class="hljs-keyword">continue</span>
        }
        <span class="hljs-keyword">throw</span> er
      }
    }
  }})(fs.readSync)
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">patchLchmod</span> (<span class="hljs-params">fs</span>) </span>{
  fs.lchmod = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">path, mode, callback</span>) </span>{
    fs.open( path
           , constants.O_WRONLY | constants.O_SYMLINK
           , mode
           , <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err, fd</span>) </span>{
      <span class="hljs-keyword">if</span> (err) {
        <span class="hljs-keyword">if</span> (callback) callback(err)
        <span class="hljs-keyword">return</span>
      }
      <span class="hljs-comment">// prefer to return the chmod error, if one occurs,</span>
      <span class="hljs-comment">// but still try to close, and report closing errors if they occur.</span>
      fs.fchmod(fd, mode, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err</span>) </span>{
        fs.close(fd, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err2</span>) </span>{
          <span class="hljs-keyword">if</span> (callback) callback(err || err2)
        })
      })
    })
  }

  fs.lchmodSync = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">path, mode</span>) </span>{
    <span class="hljs-keyword">var</span> fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode)

    <span class="hljs-comment">// prefer to return the chmod error, if one occurs,</span>
    <span class="hljs-comment">// but still try to close, and report closing errors if they occur.</span>
    <span class="hljs-keyword">var</span> threw = <span class="hljs-literal">true</span>
    <span class="hljs-keyword">var</span> ret
    <span class="hljs-keyword">try</span> {
      ret = fs.fchmodSync(fd, mode)
      threw = <span class="hljs-literal">false</span>
    } <span class="hljs-keyword">finally</span> {
      <span class="hljs-keyword">if</span> (threw) {
        <span class="hljs-keyword">try</span> {
          fs.closeSync(fd)
        } <span class="hljs-keyword">catch</span> (er) {}
      } <span class="hljs-keyword">else</span> {
        fs.closeSync(fd)
      }
    }
    <span class="hljs-keyword">return</span> ret
  }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">patchLutimes</span> (<span class="hljs-params">fs</span>) </span>{
  <span class="hljs-keyword">if</span> (constants.hasOwnProperty(<span class="hljs-string">&quot;O_SYMLINK&quot;</span>)) {
    fs.lutimes = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">path, at, mt, cb</span>) </span>{
      fs.open(path, constants.O_SYMLINK, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">er, fd</span>) </span>{
        <span class="hljs-keyword">if</span> (er) {
          <span class="hljs-keyword">if</span> (cb) cb(er)
          <span class="hljs-keyword">return</span>
        }
        fs.futimes(fd, at, mt, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">er</span>) </span>{
          fs.close(fd, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">er2</span>) </span>{
            <span class="hljs-keyword">if</span> (cb) cb(er || er2)
          })
        })
      })
    }

    fs.lutimesSync = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">path, at, mt</span>) </span>{
      <span class="hljs-keyword">var</span> fd = fs.openSync(path, constants.O_SYMLINK)
      <span class="hljs-keyword">var</span> ret
      <span class="hljs-keyword">var</span> threw = <span class="hljs-literal">true</span>
      <span class="hljs-keyword">try</span> {
        ret = fs.futimesSync(fd, at, mt)
        threw = <span class="hljs-literal">false</span>
      } <span class="hljs-keyword">finally</span> {
        <span class="hljs-keyword">if</span> (threw) {
          <span class="hljs-keyword">try</span> {
            fs.closeSync(fd)
          } <span class="hljs-keyword">catch</span> (er) {}
        } <span class="hljs-keyword">else</span> {
          fs.closeSync(fd)
        }
      }
      <span class="hljs-keyword">return</span> ret
    }

  } <span class="hljs-keyword">else</span> {
    fs.lutimes = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">_a, _b, _c, cb</span>) </span>{ <span class="hljs-keyword">if</span> (cb) process.nextTick(cb) }
    fs.lutimesSync = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{}
  }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">chmodFix</span> (<span class="hljs-params">orig</span>) </span>{
  <span class="hljs-keyword">if</span> (!orig) <span class="hljs-keyword">return</span> orig
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">target, mode, cb</span>) </span>{
    <span class="hljs-keyword">return</span> orig.call(fs, target, mode, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">er</span>) </span>{
      <span class="hljs-keyword">if</span> (chownErOk(er)) er = <span class="hljs-literal">null</span>
      <span class="hljs-keyword">if</span> (cb) cb.apply(<span class="hljs-keyword">this</span>, <span class="hljs-built_in">arguments</span>)
    })
  }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">chmodFixSync</span> (<span class="hljs-params">orig</span>) </span>{
  <span class="hljs-keyword">if</span> (!orig) <span class="hljs-keyword">return</span> orig
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">target, mode</span>) </span>{
    <span class="hljs-keyword">try</span> {
      <span class="hljs-keyword">return</span> orig.call(fs, target, mode)
    } <span class="hljs-keyword">catch</span> (er) {
      <span class="hljs-keyword">if</span> (!chownErOk(er)) <span class="hljs-keyword">throw</span> er
    }
  }
}


<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">chownFix</span> (<span class="hljs-params">orig</span>) </span>{
  <span class="hljs-keyword">if</span> (!orig) <span class="hljs-keyword">return</span> orig
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">target, uid, gid, cb</span>) </span>{
    <span class="hljs-keyword">return</span> orig.call(fs, target, uid, gid, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">er</span>) </span>{
      <span class="hljs-keyword">if</span> (chownErOk(er)) er = <span class="hljs-literal">null</span>
      <span class="hljs-keyword">if</span> (cb) cb.apply(<span class="hljs-keyword">this</span>, <span class="hljs-built_in">arguments</span>)
    })
  }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">chownFixSync</span> (<span class="hljs-params">orig</span>) </span>{
  <span class="hljs-keyword">if</span> (!orig) <span class="hljs-keyword">return</span> orig
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">target, uid, gid</span>) </span>{
    <span class="hljs-keyword">try</span> {
      <span class="hljs-keyword">return</span> orig.call(fs, target, uid, gid)
    } <span class="hljs-keyword">catch</span> (er) {
      <span class="hljs-keyword">if</span> (!chownErOk(er)) <span class="hljs-keyword">throw</span> er
    }
  }
}


<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">statFix</span> (<span class="hljs-params">orig</span>) </span>{
  <span class="hljs-keyword">if</span> (!orig) <span class="hljs-keyword">return</span> orig
  <span class="hljs-comment">// Older versions of Node erroneously returned signed integers for</span>
  <span class="hljs-comment">// uid + gid.</span>
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">target, cb</span>) </span>{
    <span class="hljs-keyword">return</span> orig.call(fs, target, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">er, stats</span>) </span>{
      <span class="hljs-keyword">if</span> (!stats) <span class="hljs-keyword">return</span> cb.apply(<span class="hljs-keyword">this</span>, <span class="hljs-built_in">arguments</span>)
      <span class="hljs-keyword">if</span> (stats.uid &lt; <span class="hljs-number">0</span>) stats.uid += <span class="hljs-number">0x100000000</span>
      <span class="hljs-keyword">if</span> (stats.gid &lt; <span class="hljs-number">0</span>) stats.gid += <span class="hljs-number">0x100000000</span>
      <span class="hljs-keyword">if</span> (cb) cb.apply(<span class="hljs-keyword">this</span>, <span class="hljs-built_in">arguments</span>)
    })
  }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">statFixSync</span> (<span class="hljs-params">orig</span>) </span>{
  <span class="hljs-keyword">if</span> (!orig) <span class="hljs-keyword">return</span> orig
  <span class="hljs-comment">// Older versions of Node erroneously returned signed integers for</span>
  <span class="hljs-comment">// uid + gid.</span>
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">target</span>) </span>{
    <span class="hljs-keyword">var</span> stats = orig.call(fs, target)
    <span class="hljs-keyword">if</span> (stats.uid &lt; <span class="hljs-number">0</span>) stats.uid += <span class="hljs-number">0x100000000</span>
    <span class="hljs-keyword">if</span> (stats.gid &lt; <span class="hljs-number">0</span>) stats.gid += <span class="hljs-number">0x100000000</span>
    <span class="hljs-keyword">return</span> stats;
  }
}

<span class="hljs-comment">// ENOSYS means that the fs doesn&apos;t support the op. Just ignore</span>
<span class="hljs-comment">// that, because it doesn&apos;t matter.</span>
<span class="hljs-comment">//</span>
<span class="hljs-comment">// if there&apos;s no getuid, or if getuid() is something other</span>
<span class="hljs-comment">// than 0, and the error is EINVAL or EPERM, then just ignore</span>
<span class="hljs-comment">// it.</span>
<span class="hljs-comment">//</span>
<span class="hljs-comment">// This specific case is a silent failure in cp, install, tar,</span>
<span class="hljs-comment">// and most other unix tools that manage permissions.</span>
<span class="hljs-comment">//</span>
<span class="hljs-comment">// When running as root, or if other types of errors are</span>
<span class="hljs-comment">// encountered, then it&apos;s strict.</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">chownErOk</span> (<span class="hljs-params">er</span>) </span>{
  <span class="hljs-keyword">if</span> (!er)
    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>

  <span class="hljs-keyword">if</span> (er.code === <span class="hljs-string">&quot;ENOSYS&quot;</span>)
    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>

  <span class="hljs-keyword">var</span> nonroot = !process.getuid || process.getuid() !== <span class="hljs-number">0</span>
  <span class="hljs-keyword">if</span> (nonroot) {
    <span class="hljs-keyword">if</span> (er.code === <span class="hljs-string">&quot;EINVAL&quot;</span> || er.code === <span class="hljs-string">&quot;EPERM&quot;</span>)
      <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
  }


 <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
}
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../chapter-1/" class="navigation navigation-prev " aria-label="Previous page: 1.3 第三节">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="./" class="navigation navigation-next " aria-label="Next page: 2.2 第二节">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"2.1 第一节","level":"2.1","depth":1,"next":{"title":"2.2 第二节","level":"2.2","depth":1,"path":"chapter-2/README.md","ref":"chapter-2/README.md","articles":[]},"previous":{"title":"1.3 第三节","level":"1.3","depth":1,"path":"chapter-1/README.md","ref":"chapter-1/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["search-pro","code","expandable-chapters","back-to-top-button"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"search-pro":{},"search":{"maxIndexSize":1000000},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"back-to-top-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"景智君","lang":"zh-cn","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"图书编号","variables":{},"title":"这是我的第一本gitbook","gitbook":"*","description":"描述"},"file":{"path":"chapter-2/ch2.md","mtime":"2021-08-04T03:17:22.811Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-08-04T03:36:50.209Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/buttons.js"></script>
        
    

    </body>
</html>

